# -*- coding: utf-8 -*-

# TODO: remove python agent attribute from header

import urllib,urllib2
from datetime import datetime

from mhd.models import MHD_Stop_Type, MHD_Link, MHD_Stop, MHD_Link_Stop
from mhd.parser import MHD_RouteParser
from web.service.HttpReader import HttpReader
from mhd.locator import MHD_StopLocator

mhd_stop_locator = MHD_StopLocator()
mhd_stop_a = mhd_stop_locator.find_nearest_stop(street = u'Ožvoldíkova', streetNum = '6', city = u'Bratislava')
mhd_stop_b = mhd_stop_locator.find_nearest_stop(street = u'Znievska', streetNum = '23', city = u'Bratislava')

#url = 'http://www.imhd.zoznam.sk/ba/index.php'
#url = 'http://www.imhd.zoznam.sk/ba/index.php?w=3825242e29ef21292e252a2f3033ef2f302523ea&lang=&z1x=pri+krizi&z2x=peknikova&odpr=0&datum=06.05.2011&cas=15%3A54&mnp=2&np=5&ptyp=0&rch=1'
#url = 'http://www.imhd.zoznam.sk/ba/index.php?w=3825242e29ef21292e252a2f3033ef2f302523ea&lang=&z1x=pri+krizi&z2x=peknikova&odpr=0&datum=06.05.2011&cas=15%3A54&mnp=2&np=5&ptyp=0&rch=1'


parameters = {'w':'3825242e29ef21292e252a2f3033ef2f302523ea', 'lang':'', 
              'z1x':u'Pri kríži', 'z2x':u'Pekníkova', 'odpr':0, 
              'datum': datetime.now().strftime("%m.%d.%Y"), 'cas': '17:00',
              'mnp':2, 'np':5, 'ptyp':0, 'rch':1}    

httpReader = HttpReader()
data = httpReader.read(url = url)

mhd_routeParser = MHD_RouteParser()
#print data.decode('cp1250')
route_connections = mhd_routeParser.parse(data.decode('cp1250'))
print route_connections


#data = urllib.urlencode(parameters)
#request = urllib2.Request(url, data)
#response = urllib2.urlopen(request)

#print response.read().decode('cp1250')
#print data.decode('cp1250')    
